Questions
14 of 25
1How do you implement a local (username/password) Passport strategy in NestJS?
2How do you register a global JWT guard so all routes are protected by default in NestJS?
3What is RBAC and how do you implement a basic roles guard in NestJS?
4What is the difference between RBAC and ABAC and when would you use each in NestJS?
5How does the OAuth2 authorization code flow work and how do you implement it with Passport in NestJS?
6How do you implement API key authentication as an alternative to JWT in NestJS?
7How do you implement multi-tenant authentication where each tenant has its own JWT secret in NestJS?
8How do you implement JWT refresh token rotation with secure storage in NestJS?
9How do you implement ABAC with CASL in a NestJS application?
10What is the difference between JWT and session-based authentication and when do you choose each in NestJS?
11How do you implement two-factor authentication (2FA) with TOTP in NestJS?
12How do you implement permission-based authorization at the field level in a GraphQL resolver in NestJS?
13How do you test authentication guards and strategies in NestJS?
14What is Passport.js and how does it integrate with NestJS?
15How do you implement row-level (resource-level) authorization to ensure users can only access their own records in NestJS?
16What is PKCE and when is it required in OAuth2 flows in NestJS?
17How do you implement an OAuth2 Authorization Server in NestJS?
18How do you implement session-based authentication in NestJS?
19How does the validate() method in a Passport strategy relate to the NestJS request lifecycle?
20How do you implement JWT authentication in NestJS with access and refresh tokens?
21What should and should not go inside a JWT payload?
22How do you implement JWT token revocation (blacklisting) without a database lookup on every request in NestJS?
23What is the difference between AuthGuard('jwt') from Passport and writing a custom JwtAuthGuard in NestJS?
24How do you secure session cookies against common attacks (CSRF, XSS, session fixation) in NestJS?
25How do you implement brute force protection on the login endpoint in NestJS?
14 / 25

What is Passport.js and how does it integrate with NestJS?

Passport is a Node.js authentication middleware that delegates authentication to pluggable strategies. NestJS wraps Passport via @nestjs/passport, bridging strategies into the NestJS guard and DI system. Each strategy is an @Injectable() provider that extends PassportStrategy(). The validate() return value becomes request.user.

AuthModule setup with Passport
How NestJS integrates with Passport:
  1. 1

    Each Passport strategy is an @Injectable() NestJS provider extending PassportStrategy(Strategy, 'name').

  2. 2

    PassportModule.register({ defaultStrategy }) sets the strategy used when no explicit name is given to AuthGuard().

  3. 3

    NestJS turns the strategy's validate() return value into the request.user object.

  4. 4

    AuthGuard('strategy-name') wraps a Passport strategy as a NestJS guard — canActivate() delegates to Passport.

  5. 5

    Strategies have full DI support — inject UsersService, ConfigService, or any other provider in the constructor.